/*
* HorizontalScrollNumberTiles
*
* Copyright (C) Connect Link 2013-
*/


package com.connectlinkcorp.common.ui.horizontalscrollnumbertiles;

import java.util.ArrayList;

import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.HorizontalScrollView;
import android.widget.LinearLayout;
import android.widget.Toast;

public class HorizontalScrollNumberTiles extends LinearLayout{

	private Context context;
	private int numberOfDisplay;
	private int positionX;
	private int positionY;
	private int width;
	private int height;
	private int [] imageDigit;
	private ArrayList<Integer> numbers;
	private HorizontalScrollView horiScrView;
	private LinearLayout liItems;
	private ArrayList<Button> btnDigits;
	
	public HorizontalScrollNumberTiles(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
		numbers = new ArrayList<Integer>();
		this.context = context;
	}
	
	public HorizontalScrollNumberTiles(Context context, AttributeSet  attr){
		super(context, attr);
		this.context = context;
	}
	
	/*
	 * HorizontalScrollNumberTiles
	 */
	public HorizontalScrollNumberTiles(Context context,int numberOfDisplay,int positionX,
			int positionY,int width,int height,ArrayList<Integer> numbers) {
		super(context);
		// TODO Auto-generated constructor stub
		numbers = new ArrayList<Integer>();
		this.context = context;
		this.numberOfDisplay = numberOfDisplay;
		this.positionX = positionX;
		this.positionY = positionY;
		this.width = width;
		this.height = height;
		this.numbers = numbers;
	}
	
	/*
	 * setUpParam
	 */
	public void setUpParam(Context context,int numberOfDisplay,int positionX,
			int positionY,int width,int height,ArrayList<Integer> numbers) {
		// TODO Auto-generated constructor stub
//		numbers = new ArrayList<Integer>();
		this.context = context;
		this.numberOfDisplay = numberOfDisplay;
		this.positionX = positionX;
		this.positionY = positionY;
		this.width = width;
		this.height = height;
		this.numbers = numbers;
	}
	/*
	 * 
	 */
	public void show (){
		liItems = new LinearLayout(context);
		horiScrView = new HorizontalScrollView(context);
		horiScrView.addView(liItems);
		this.addView(horiScrView);
		
		LayoutParams paramsHori = new LayoutParams(width, height);
		paramsHori.setMargins(positionX, positionY, 0, 0);
		paramsHori.gravity = Gravity.CENTER;
		horiScrView.setLayoutParams(paramsHori);
		//horiScrView.
		
		btnDigits = new ArrayList<Button>();
		liItems.removeAllViews();
		
		int size = width/numberOfDisplay;
		for(int i = 0;i < numbers.size();i++){
			Button btnTemp = new Button(context);
			LayoutParams params = new LayoutParams(size,size);
			btnTemp.setLayoutParams(params);
			btnTemp.setId(i);
			btnTemp.setBackgroundResource(imageDigit[numbers.get(i)]);
			liItems.addView(btnTemp);
			btnDigits.add(btnTemp);
		}
	}
	
	
	public int getNumberOfDisplay() {
		return numberOfDisplay;
	}


	public void setNumberOfDisplay(int numberOfDisplay) {
		this.numberOfDisplay = numberOfDisplay;
	}


	public int getPositionX() {
		return positionX;
	}


	public void setPositionX(int positionX) {
		this.positionX = positionX;
	}


	public int getPositionY() {
		return positionY;
	}


	public void setPositionY(int positionY) {
		this.positionY = positionY;
	}


	public int getWidthOfView() {
		return width;
	}


	public void setWidthOfView(int width) {
		this.width = width;
	}


	public int getHeightOfView() {
		return height;
	}


	public void setHeightOfView(int length) {
		this.height = length;
	}

	public int[] getImageDigit() {
		return imageDigit;
	}
	public void setImageDigit(int[] imageDigit) {
		this.imageDigit = imageDigit;
	}
	
	public ArrayList<Integer> getNumbers() {
		return numbers;
	}


	public void setNumbers(ArrayList<Integer> numbers) {
		this.numbers = numbers;
	}
	
	public void setItemClicked (OnClickListener onClick) {
		if (btnDigits.size() > 0) {
			for (int i = 0; i < btnDigits.size(); i ++) {
				btnDigits.get(i).setOnClickListener(onClick);
			}
		}
	}
	
}
